<?php


namespace app\admin\system\validate;


use support\exception\BadException;
use think\Validate;

class BaseValidate extends Validate
{
    /**
     * 默认规则提示
     * @var array
     */
    protected $typeMsg = [
        'require'     => ':attribute 不能为空',
        'must'        => '请传入 :attribute 字段',
        'number'      => ':attribute 必须是数字',
        'integer'     => ':attribute 必须是整数',
        'float'       => ':attribute 必须是小数',
        'boolean'     => ':attribute must be bool',
        'email'       => ':attribute 必须是合法的email格式',
        'mobile'      => ':attribute 不是一个合法的手机号',
        'array'       => ':attribute 不是一个数组',
        'accepted'    => ':attribute must be yes,on or 1',
        'date'        => ':attribute 不是一个合法的时间格式',
        'file'        => ':attribute 不是一个文件',
        'image'       => ':attribute 不是一个图片',
        'alpha'       => ':attribute must be alpha',
        'alphaNum'    => ':attribute must be alpha-numeric',
        'alphaDash'   => ':attribute must be alpha-numeric, dash, underscore',
        'activeUrl'   => ':attribute not a valid domain or ip',
        'chs'         => ':attribute 不是中文',
        'chsAlpha'    => ':attribute must be chinese or alpha',
        'chsAlphaNum' => ':attribute must be chinese,alpha-numeric',
        'chsDash'     => ':attribute must be chinese,alpha-numeric,underscore, dash',
        'url'         => ':attribute 不是一个合法的 url',
        'ip'          => ':attribute 不是一个合法的 ip',
        'dateFormat'  => ':attribute must be dateFormat of :rule',
        'in'          => ':attribute 必须在 :rule 之内',
        'notIn'       => ':attribute 不能在 :rule 之内',
        'between'     => ':attribute必须在:1 - :2之间',
        'notBetween'  => ':attribute不能在:1 - :2之间',
        'length'      => ':attribute长度必须在:rule位数',
        'max'         => ':attribute最大:rule位数',
        'min'         => ':attribute最少:rule位数',
        'after'       => ':attribute cannot be less than :rule',
        'before'      => ':attribute cannot exceed :rule',
        'expire'      => ':attribute not within :rule',
        'allowIp'     => 'access IP is not allowed',
        'denyIp'      => 'access IP denied',
        'confirm'     => ':attribute out of accord with :2',
        'different'   => ':attribute cannot be same with :2',
        'egt'         => ':attribute 必须大于等于 :rule',
        'gt'          => ':attribute 必须大于 :rule',
        'elt'         => ':attribute 必须小于等于 :rule',
        'lt'          => ':attribute 必须小于 :rule',
        'eq'          => ':attribute 必须等于 :rule',
        'unique'      => ':attribute has exists',
        'regex'       => ':attribute not conform to the rules',
        'method'      => 'invalid Request method',
        'token'       => 'invalid token',
        'fileSize'    => 'filesize not match',
        'fileExt'     => 'extensions to upload is not allowed',
        'fileMime'    => 'mimetype to upload is not allowed',
    ];


    public static function goCheck($data)
    {
        $validate = new static();
        if (!$validate->check($data)) {
           throw new BadException($validate->getError());
        }
    }
}